home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Tool Chest / Development Tools & Languages / Dylan Related / Mindy-1.1 (sources only) / mindy-1.1 / libraries / streams / internals.dylan < prev    next >
Encoding:
Text File  |  1994-08-25  |  3.5 KB  |  107 lines  |  [TEXT/ttxt]

  1. module: Internals
  2. author: chiles@cs.cmu.edu
  3. synopsis: This file implements some extensions to the Gwydion Dylan
  4.           implementation.
  5. copyright: See below.
  6. rcs-header: $Header: internals.dylan,v 1.7 94/08/23 10:34:15 chiles Exp $
  7.  
  8. //======================================================================
  9. //
  10. // Copyright (c) 1994  Carnegie Mellon University
  11. // All rights reserved.
  12. // 
  13. // Use and copying of this software and preparation of derivative
  14. // works based on this software are permitted, including commercial
  15. // use, provided that the following conditions are observed:
  16. // 
  17. // 1. This copyright notice must be retained in full on any copies
  18. //    and on appropriate parts of any derivative works.
  19. // 2. Documentation (paper or online) accompanying any system that
  20. //    incorporates this software, or any part of it, must acknowledge
  21. //    the contribution of the Gwydion Project at Carnegie Mellon
  22. //    University.
  23. // 
  24. // This software is made available "as is".  Neither the authors nor
  25. // Carnegie Mellon University make any warranty about the software,
  26. // its performance, or its conformity to any specification.
  27. // 
  28. // Bug reports, questions, comments, and suggestions should be sent by
  29. // E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  30. //
  31. //======================================================================
  32. //
  33.  
  34.  
  35.  
  36. ///
  37. /// Classes and types.
  38. ///
  39.  
  40. define constant <fixed-integer> = <integer>;
  41.  
  42. /// This isn't totally right because William plans for fixed-integers to be
  43. /// larger on 64-bit machines.
  44. ///
  45. define constant $maximum-fixed-integer = #x3FFFFFF;
  46.  
  47. define constant <byte> =
  48.   limited(<fixed-integer>, min: 0, max: 255);
  49.  
  50. /// In the bootstrap environment, <character> is exactly what we want
  51. /// <byte-character> to be.  In the real Dylan implementation, this will have
  52. /// to be a distinct class.
  53. ///
  54. define constant <byte-character> = <character>;
  55.  
  56.  
  57. ///
  58. /// As methods.
  59. ///
  60.  
  61. define method as (result :: singleton(<byte>), object :: <byte-character>)
  62.     => result :: <byte>;
  63.   as(<integer>, object);
  64. end method;
  65.  
  66. define method as (result :: singleton(<byte-string>), object :: <byte-vector>)
  67.     => result :: <byte-string>;
  68.   let len :: <fixed-integer> = object.size;
  69.   let res :: <byte-string> = make(<byte-string>, size: len);
  70.   copy-bytes(res, 0, object, 0, len);
  71. end method;
  72.  
  73. define method as (result :: singleton(<byte-vector>), object :: <byte-string>)
  74.     => result :: <byte-vector>;
  75.   let len :: <fixed-integer> = object.size;
  76.   let res :: <byte-vector> = make(<byte-vector>, size: len);
  77.   copy-bytes(res, 0, object, 0, len);
  78. end method;
  79.  
  80.  
  81. ///
  82. /// Utilities.
  83. ///
  84.  
  85. /// call-fd-function -- Exported.
  86. ///
  87. /// This function applies the fd function to the arguments and tests the
  88. /// error code.  If there is no error, return the function's values;
  89. /// otherwise, signal an error with the unix description of the error.
  90. ///
  91. /// If we had macros, this function would be a macro and require no
  92. /// overhead.  It also would allow type propagation so that calls to these
  93. /// fd functions within expression (that is, not bound to a type-declared
  94. /// variable) would have the benefit of the return types of the fd
  95. /// functions.  As it is, we have to allocate a rest argument, do multiple
  96. /// function calls, and so on.  For now, assume the system call incurs more
  97. /// overhead, especially if William really implemented rest args as
  98. /// more-args.
  99. ///
  100. /// IGNORE MULTIPLE VALUES FOR NOW.
  101. ///
  102. define method call-fd-function (fun :: <function>, #rest args)
  103.   let (res, err) = apply(fun, args);
  104.   if (err) error(fd-error-string(err)) end;
  105.   res;
  106. end;
  107.